package week04.homework02ShapeCalculator;

import week04.homework02ShapeCalculator.shape.BaseShape;
import week04.homework02ShapeCalculator.shape.Circle;
import week04.homework02ShapeCalculator.shape.Rectangle;
import week04.homework02ShapeCalculator.shape.Triangle;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author li
 */
public class ShapeCalculator {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        List<BaseShape> shapes = new ArrayList<>();

        while (true) {
            System.out.println("1. 添加圆形 2. 添加矩形 3. 添加三角形 4. 计算所有图形的面积 5. 退出");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1 -> {
                    System.out.print("请输入圆形的半径：");
                    double radius = scanner.nextDouble();
                    Circle circle = new Circle(radius);
                    shapes.add(circle);
                }
                case 2 -> {
                    System.out.print("请输入矩形的长和宽：");
                    double length = scanner.nextDouble();
                    double width = scanner.nextDouble();
                    Rectangle rectangle = new Rectangle(length, width);
                    shapes.add(rectangle);
                }
                case 3 -> {
                    System.out.print("请输入三角形的三条边：");
                    double a = scanner.nextDouble();
                    double b = scanner.nextDouble();
                    double c = scanner.nextDouble();
                    BaseShape triangle = new Triangle(a, b, c);
                    shapes.add(triangle);
                }
                case 4 -> shapes.forEach(shape -> System.out.println(shape.getClass().getSimpleName() + " 面积为：" + shape.getArea()));
                case 5 -> {
                    System.out.println("退出程序");
                    return;
                }
                default -> {
                }
            }
        }
    }

}
